<?php
class M_users extends CI_Model{
	
	function getlist($limit,$offset,$filter){
		$this->db->limit($limit);
		$this->db->offset($offset);
		$this->db->select('user_id, user_name,last_name,user_tetala,user_email,user_kota, user_passwd,user_groups,s_usergroups.group_name,user_active');
		$this->db->from('s_users');
		$this->db->join('s_usergroups', 's_users.user_groups = s_usergroups.group_id');
		$this->db->where('user_active','Y');
		if(!empty($filter)){
			$this->db->where("lower(`user_name`)  like '%".addslashes(strtolower($filter))."%'"); 
		}
		$query = $this->db->get();
		$total = $query->num_rows();
		$arr   = array();
		foreach($query->result() as $q){
			$arr[] = $q;
		}
		$final = array('results' => $arr, 'total' => $total);
		return json_encode($final);
	}
	function getstorecombo(){
		$this->db->select('group_id, group_name')->where('group_active','Y');
		$query = $this->db->get('s_usergroups');
		$total = $query->num_rows();
		$arr   = array();
		foreach($query->result() as $q){
			$arr[] = $q;
		}
		$final = array('results' => $arr,'total' => $total);
		return json_encode($final);
	}
	
	function insert($data){
		$this->db->insert('s_users',$data);
	}
	function edit($data, $user_id){
		$this->db->where('user_id',$user_id);
		$this->db->update('s_users',$data);
	}
}